package cn.tedu._04weibo.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


//方法注解@Data一次性生成get set tostring方法
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {//状态码 提示消息 具体数据
    private Integer state;
    private String message;
    private Object data;
//没有数据返回的
public JsonResult(StatusCode statusCode) {
    this.state = statusCode.getState();
    this.message = statusCode.getMessage();
    this.data = null;
    }
    //有数据返回的
    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    //封装两个静态方法 1操作成功没有具体返回控制器 2操作成功有具体数据返回的控制器方法
    public static  JsonResult ok(){
    return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }
    public static JsonResult ok(Object data){
    return new JsonResult(StatusCode.OPERATION_SUCCESS,data);

    }

}
